<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>备品备件</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<style type="text/css">
		.left-label {
			width: 100px !important
		}
	</style>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
	<div class="layui-inline">
		<input class="layui-input" name="keyword" id="keyword" placeholder="请输入产品名称" style="display: inline; width: 100%">
	</div>
	<button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">搜索</i></button>
</div>
<table class="layui-hide" id="tableList" lay-filter="tableList"></table>

<div class="demoTable" style="padding:10px 0 0 15px">
	<div class="layui-inline">
		<input class="layui-input" name="keyword2" id="keyword2" placeholder="请输入产品名称" style="display: inline; width: 100%">
	</div>
	<button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload2"><i class="layui-icon layui-icon-search">搜索</i></button>
</div>
<table class="layui-hide" id="tableList2" lay-filter="tableList2"></table>
<!-- 增加 -->
<div id="addDivID" hidden="hidden">
	<form class="layui-form" id="addFormID">
		<table>
			<tr>
				<td><label class="layui-form-label left-label" style="margin-top: 20px">产品编号</label></td>
				<td><input class="layui-input" id="productNo1" name="productNo" lay-verify="productNo" style="width:150px; margin-top:20px; display: inline;">
					<div class="layui-inline" style="margin-top: 5px;">
						<font style="color:red; font-size: 24px; margin-left: 4px">*</font>
					</div>
				</td>
				<td><label class="layui-form-label" style="margin-top: 20px">产品名称</label></td>
				<td><input class="layui-input" id="productName1" name="productName" lay-verify="productName" style="width:150px; margin-top:20px; display: inline;">
					<div class="layui-inline" style="margin-top: 5px;">
						<font style="color:red; font-size: 24px; margin-left: 4px">*</font>
					</div>
				</td>
			</tr>
			<tr style="height:20px"></tr>
			<tr>
				<td>&emsp;&emsp;&emsp;&emsp;产品条码&emsp;</td>
				<td><input class="layui-input" id="barCode1" name="barCode" lay-verify="barCode" style="width:150px"></td>
				<td>&emsp;&emsp;&emsp;&emsp;批次号&emsp;</td>
				<td><input class="layui-input" id="batchNum1" name="batchNum" lay-verify="batchNum" style="width:150px"></td>
			</tr>
			<tr style="height:20px"></tr>
			<tr>
				<td>&emsp;&emsp;&emsp;&emsp;产品厂家&emsp;</td>
				<td><input class="layui-input" id="vender1" name="vender" lay-verify="vender" style="width:150px"></td>
				<td>&emsp;&emsp;&emsp;&emsp;产品数量&emsp;</td>
				<td><input class="layui-input" id="productCount1" name="productCount" lay-verify="productCount" style="width:150px; display: inline" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onafterpaste="this.value=this.value.replace(/[^\d]/g,'')">
					<div class="layui-inline" style="margin-top: 5px;">
						<font style="color:red; font-size: 24px; margin-left: 4px">*</font>
					</div>
				</td>
			</tr>
			<tr style="height:20px"></tr>
			<tr>
				<td>&emsp;&emsp;&emsp;&emsp;安全库存&emsp;</td>
				<td><input class="layui-input" id="remark011" name="remark01" lay-verify="remark01" style="width:150px; display: inline">
					<div class="layui-inline" style="margin-top: 5px;">
						<font style="color:red; font-size: 24px; margin-left: 4px">*</font>
					</div>
				</td>
				<td>&emsp;&emsp;&emsp;&emsp;进货日期&emsp;</td>
				<td><input class="layui-input" id="inProductTime1" name="inProductTime" lay-verify="inProductTime" style="width:150px"></td>
			</tr>
			<tr style="height:20px"></tr>
			<tr align="center">
				<td colspan="2"><button class="layui-btn layui-btn-blue" id="subBtn" lay-submit lay-filter="addForm" style="margin-left:160px; margin-bottom: 20px">提交</button></td>
				<td colspan="2">&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button></td>
			</tr>
		</table>
	</form>
</div>
<!-- 编辑 -->
<div id="editDivID" hidden="hidden">
	<form class="layui-form" id="editFormID">
		<table>
			<tr>
				<td><input class="layui-hide" id="id" name="id"></td>
			<tr>
			<tr>
				<td><label class="layui-form-label left-label" style="margin-top: 20px">产品编号</label></td>
				<td><input readonly class="layui-input" id="productNo2" name="productNo" lay-verify="productNo" style="width:150px; margin-top:20px; display: inline;">
					<div class="layui-inline" style="margin-top: 5px;">
						<font style="color:red; font-size: 24px; margin-left: 4px">*</font>
					</div>
				</td>
				<td><label class="layui-form-label" style="margin-top: 20px">产品名称</label></td>
				<td><input readonly class="layui-input" id="productName2" name="productName" lay-verify="productName" style="width:150px; margin-top:20px; display: inline;">
					<div class="layui-inline" style="margin-top: 5px;">
						<font style="color:red; font-size: 24px; margin-left: 4px">*</font>
					</div>
				</td>
			</tr>
			<tr style="height:20px"></tr>
			<tr>
				<td>&emsp;&emsp;&emsp;&emsp;产品条码&emsp;</td>
				<td><input class="layui-input" id="barCode2" name="barCode" lay-verify="barCode" style="width:150px"></td>
				<td>&emsp;&emsp;&emsp;&emsp;批次号&emsp;</td>
				<td><input class="layui-input" id="batchNum2" name="batchNum" lay-verify="batchNum" style="width:150px"></td>
			</tr>
			<tr style="height:20px"></tr>
			<tr>
				<td>&emsp;&emsp;&emsp;&emsp;产品厂家&emsp;</td>
				<td><input class="layui-input" id="vender2" name="vender" lay-verify="vender" style="width:150px"></td>
				<td>&emsp;&emsp;&emsp;&emsp;产品数量&emsp;</td>
				<td><input class="layui-input" id="productCount2" name="productCount" lay-verify="productCount" style="width:150px; display: inline" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onafterpaste="this.value=this.value.replace(/[^\d]/g,'')">
					<div class="layui-inline" style="margin-top: 5px;">
						<font style="color:red; font-size: 24px; margin-left: 4px">*</font>
					</div>
				</td>
			</tr>
			<tr style="height:20px"></tr>
			<tr>
				<td>&emsp;&emsp;&emsp;&emsp;安全库存&emsp;</td>
				<td><input class="layui-input" id="remark012" name="remark01" lay-verify="remark01" style="width:150px; display: inline">
					<div class="layui-inline" style="margin-top: 5px;">
						<font style="color:red; font-size: 24px; margin-left: 4px">*</font>
					</div>
				</td>
				<td>&emsp;&emsp;&emsp;&emsp;进货日期&emsp;</td>
				<td><input class="layui-input" id="inProductTime2" name="inProductTime" lay-verify="inProductTime" style="width:150px"></td>
			</tr>
			<tr style="height:20px"></tr>
			<tr align="center">
				<td colspan="2"><button class="layui-btn layui-btn-blue" id="subBtn" lay-submit lay-filter="editForm" style="margin-left:160px; margin-bottom: 20px">提交</button></td>
				<td colspan="2">&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button></td>
			</tr>
		</table>
	</form>
</div>
<!-- 维修 -->
<div id="repairDivID" hidden="hidden">
	<form class="layui-form" id="repairFormID">
		<table style="margin-top: 10px">
			<tr>
				<td><label class="layui-form-label left-label">产品编号</label></td>
				<td>
					<div style="width: 170px">
						<div style="width: 150px; margin-left: 0px; float: left;">
							<select class="layui-select" id="productNo" name="productNo" lay-filter="displayInfo" lay-verify="productNo">
								<option value="">请选择</option>
							</select>
						</div>
						<div style="margin-top: 9px; float: left">
							<font style="color:red; font-size: 24px; margin-left: 4px">*</font>
						</div>
					</div>
				</td>
				<td><label class="layui-form-label left-label">产品名称</label></td>
				<td><input class="layui-input" id="productName" name="productName" lay-verify="productName" style="width:150px; display: inline;">
					<div class="layui-inline" style="margin-top: 5px;">
						<font style="color:red; font-size: 24px; margin-left: 4px">*</font>
					</div>
				</td>
			</tr>
			<tr style="height:20px"></tr>
			<tr>
				<td>&emsp;&emsp;&emsp;&emsp;维修数量&emsp;</td>
				<td><input class="layui-input" id="productCount" name="productCount" lay-verify="productCount" style="width:150px; display: inline;"; onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onafterpaste="this.value=this.value.replace(/[^\d]/g,'')">
					<div class="layui-inline" style="margin-top: 5px;">
						<font style="color:red; font-size: 24px; margin-left: 4px">*</font>
					</div>
				</td>
				<td>&emsp;&emsp;&emsp;&emsp;维修开始日期&emsp;</td>
				<td><input class="layui-input" id="repairStartTime" name="repairStartTime" lay-verify="repairStartTime" style="width:150px"></td>
			</tr>
			<tr style="height:20px"></tr>
			<tr>
				<td>&emsp;&emsp;&emsp;&emsp;维修结束日期&emsp;</td>
				<td><input class="layui-input" id="repairEndTime" name="repairEndTime" lay-verify="repairEndTime" style="width:150px"></td>
				<td>&emsp;&emsp;&emsp;&emsp;维修原因&emsp;</td>
				<td><input class="layui-input" id="repairReason" name="repairReason" lay-verify="repairReason" style="width:150px"></td>
			</tr>
			<tr style="height:20px"></tr>
			<tr>
				<td>&emsp;&emsp;&emsp;&emsp;维修人&emsp;</td>
				<td><input class="layui-input" id="repairMan" name="repairMan" lay-verify="repairMan" style="width:150px"></td>
				<td>&emsp;&emsp;&emsp;&emsp;备注&emsp;</td>
				<td><input class="layui-input" id="remark" name="remark" lay-verify="remark" style="width:150px"></td>
			</tr>
			<tr style="height:20px"></tr>
			<tr align="center">
				<td colspan="2"><button class="layui-btn layui-btn-blue" id="subBtn" lay-submit lay-filter="repairForm" style="margin-left:160px; margin-bottom: 20px">提交</button></td>
				<td colspan="2">&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button></td>
			</tr>
		</table>
	</form>
</div>
<div id="formDiv" hidden="hidden">
	<form class="layui-form" id="uploadform" style="text-align:center; margin-top: 20px">
		<table style="margin:auto">
			<tr style="text-align: center">
				<td colspan="2" style="text-align:center;">
					<input id="fileInput" name="file" type="file" accept=".xls,.xlsx" style="margin-left: 80px; margin-bottom: 20px"/>
				</td>
			</tr>
			<tr>
				<td style="text-align:center;">
					<button class="layui-btn layui-btn-blue" lay-submit lay-filter="uplodeform">导入</button>
				</td>
				<td style="text-align:center;">
					<button type="button" class="layui-btn" id="downloadFile">
						<i class="layui-icon"></i>下载模板
					</button>
				</td>
			</tr>
		</table>
	</form>
</div>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">新增</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="uploadExcel"><i class="layui-icon layui-icon-download-circle">导入</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="delete"><i class="layui-icon layui-icon-delete">批量删除</i></button>
	</div>
</script>

<script type="text/html" id="toolbar2">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="repair"><i class="layui-icon layui-icon-add-1">维修</i></button>
	</div>
</script>

<script type="text/html" id="rowToolbar">
	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>

<script type="text/javascript">
    layui.use(['table','layer','upload','form','laydate'], function(){
        var table = layui.table;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var form = layui.form;
        var upload = layui.upload;
        var $ = layui.jquery, active = {
            reload:function () {
                /*var searchTime = $("#searchTime").val();*/
                var keyword01 = $("#keyword").val();
                /*console.log(searchTime + ',' + keyword)*/
                table.reload('contenttable',{
                    method:'get',
                    where:{"keyword01":keyword01},
                    page: {
                        curr: 1
                    }
                });
            },
            reload2:function () {
                /*var searchTime = $("#searchTime").val();*/
                var keyword02 = $("#keyword2").val();
                /*console.log(searchTime + ',' + keyword)*/
                table.reload('contenttable2',{
                    method:'get',
                    where:{"keyword02":keyword02},
                    page: {
                        curr: 1
                    }
                });
            }
        }
        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        /* 上表 */
        table.render({
            elem: '#tableList'
            ,url:'${pageContext.request.contextPath }/spareParts/querySpareParts.do'
            ,toolbar: '#toolbar'
            ,title: '备品备件'
            ,id :'contenttable'
            ,limits:[10,20,30]
            ,cols: [[
                {type: 'checkbox', fixed: 'left', },
                {field:'', title:'序号', sort: true, type:'numbers', width: 60},
                {field:'productNo', title:'产品编号'},
                {field:'productName', title:'产品名称'},
                {field:'barCode', title:'条形码'},
                {field:'batchNum', title:'批次号'},
                {field:'vender', title:'产品厂家'},
                {field:'productCount', title:'产品数量'},
                {field:'remark01', title:'安全库存'},
                {field:'inProductTime', title:'进货日期'},
                {fixed:'right', title:'操作', toolbar: '#rowToolbar', width: 110}
            ]],
            page: true
        });

        /* 下表 */
        table.render({
            elem: '#tableList2'
            ,url:'${pageContext.request.contextPath }/spareParts/querySparePartsRepair.do'
            ,toolbar: '#toolbar2'
            ,title: '备品备件维修'
            ,id :'contenttable2'
            ,limits:[10,20,30]
            ,cols: [[
                {type: 'checkbox', fixed: 'left', },
                {field:'', title:'序号', sort: true, type:'numbers', width: 60},
                {field:'productNo', title:'备品备件编号'},
                {field:'productName', title:'备品备件名称'},
                {field:'productCount', title:'维修备品备件数量'},
                {field:'repairStartTime', title:'维修开始时间'},
                {field:'repairEndTime', title:'维修结束时间'},
                {field:'repairReason', title:'维修原因'},
                {field:'repairMan', title:'维修人'},
                {field:'remark', title:'备注'}
            ]],
            page: true
        });

        //头工具栏事件1
        table.on('toolbar(tableList)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                //导入
                case 'uploadExcel':
                    layer.open({
                        type: 1 		//Page层类型
                        ,area: ['500px', '200px'] //宽  高
                        ,title: '导入'
                        ,shade: 0.6 	//遮罩透明度
                        ,maxmin: true 	//允许全屏最小化
                        ,anim: 1 		//0-6的动画形式，-1不开启
                        ,content: $('#formDiv')
                        ,end: function () {
                            var formDiv = document.getElementById('formDiv');
                            formDiv.style.display = '';
                        }
                    });
                    break;
                //新增
                case 'add':
                    layer.open({
                        type: 1 					//Page层类型
                        ,area: ['620px', '400px'] 		//宽  高
                        ,title: '新增'
                        ,shade: 0.6 				//遮罩透明度
                        ,maxmin: true 				//允许全屏最小化
                        ,anim: 1 					//0-6的动画形式，-1不开启
                        ,content: $("#addDivID")
                        ,end: function(){
                            $("#addDivID").hide();
                        }
                        ,success: function(){

                        }
                    });
                    break;
                //批量删除
                case 'delete':
                    var data = checkStatus.data;
                    var idArr = new Array();
                    if(data.length == 0){
                        toastr.warning("请至少选择一条记录！");
                    }
                    for(var i=0;i < data.length;i++){
                        /*alert(data[i].id)*/
                        idArr[i] = data[i].id;
                    }
                    $.ajax({
                        type:'post',
                        url:'${pageContext.request.contextPath }/spareParts/deleteSparePartsById.do',
                        data:{"idArr" : idArr},
                        success:function(data){
                            layer.confirm('确定删除吗？', function(index){
                                if(data > 0){
                                    toastrStyle();
                                    toastr.success("删除成功！");
                                    setTimeout(function(){
                                        location.reload();
                                    },1000);
                                }else{
                                    toastrStyle();
                                    toastr.warning("删除失败！");
                                    setTimeout(function(){
                                        location.reload();
                                    },1000);
                                }
                            });
                        }
                    });
                    break;
                /* case 'repair':
                    layer.open({
                        type: 1 					//Page层类型
                          ,area: ['40%', '48%'] 		//宽  高
                          ,title: '维修'
                          ,shade: 0.6 				//遮罩透明度
                          ,maxmin: true 				//允许全屏最小化
                          ,anim: 1 					//0-6的动画形式，-1不开启
                          ,content: $("#repairDivID")
                          ,end: function(){
                              $("#repairDivID").hide();
                          }
                          ,success: function(){

                          }
                });
                  break; */
            };
        });

        //头工具栏事件2
        table.on('toolbar(tableList2)', function(obj){
            $("#productNo").find("option").not(":first").remove();
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'repair':
                    layer.open({
                        type: 1 					//Page层类型
                        ,area: ['650px', '380px'] 		//宽  高
                        ,title: '维修'
                        ,shade: 0.6 				//遮罩透明度
                        ,maxmin: true 				//允许全屏最小化
                        ,anim: 1 					//0-6的动画形式，-1不开启
                        ,content: $("#repairDivID")
                        ,end: function(){
                            $("#repairDivID").hide();
                        }
                        ,success: function(){
                            //页面加载时加载下拉框
                            $.ajax({
                                type: 'POST',
                                url: '${pageContext.request.contextPath}/spareParts/queryAllSparePartsList.do',
                                dataType: 'json',
                                async: false,
                                success: function (data){
                                    for (var i = 0; i < data.length; i++) {
                                        $("#productNo").append("<option value='"+ data[i].productNo +"'>"+ data[i].productNo +"</option>");
                                    }
                                }
                            });
                            form.render();
                        }
                    });
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(tableList)', function(obj){
            var idArr = new Array();
            //单个删除
            if(obj.event === 'del'){
                var data = obj.data;
                layer.confirm('确定删除吗？', function(index){
                    var id = obj.data.id;
                    idArr[0] = id;
                    $.ajax({
                        type:'post',
                        url:'${pageContext.request.contextPath }/spareParts/deleteSparePartsById.do',
                        data:{ "idArr" : idArr },
                        success:function(data){
                            if(data > 0){
                                toastrStyle();
                                toastr.success("删除成功！");
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                            }else{
                                toastrStyle();
                                toastr.warning("删除失败！");
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                            }
                        }
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                var data = obj.data;
                layer.open({
                    type: 1 				//Page层类型
                    ,area: ['620px', '400px']	//宽  高
                    ,title: '编辑'
                    ,shade: 0.6 			//遮罩透明度
                    ,maxmin: true 			//允许全屏最小化
                    ,anim: 1 				//0-6的动画形式，-1不开启
                    ,content: $("#editDivID")
                    ,end: function(){
                        $("#editDivID").hide();
                    }
                    ,success: function(){
                        $("#id").val(data.id);
                        $("#productName2").val(data.productName);
                        $("#productNo2").val(data.productNo);
                        $("#barCode2").val(data.barCode);
                        $("#batchNum2").val(data.batchNum);
                        $("#vender2").val(data.vender);
                        $("#productCount2").val(data.productCount);
                        $("#remark012").val(data.remark01);
                        //var newInProductTime = createTime(data.inProductTime);
                        $("#inProductTime2").val(data.inProductTime);
                    }
                });
            }
        });

        /**
         * 通用表单提交(AJAX方式)(新增)
         */
        form.on('submit(addForm)', function (data) {
            $("#subBtn").attr("disabled",true);
            $.ajax({
                url : '${pageContext.request.contextPath}/spareParts/addSpareParts.do',
                data: $("#addFormID").serialize(),
                cache : false,
                type : "post",
            }).done(
                function(res) {
                    if (res > 0) {
                        toastrStyle();
                        toastr.success('新增成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function(res) {
                    toastrStyle();
                    toastr.error('新增失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        });
        /**
         * 通用表单提交(AJAX方式)(修改)
         */
        form.on('submit(editForm)', function (data) {
            $.ajax({
                url : '${pageContext.request.contextPath}/spareParts/editSparePartsById.do',
                data: $("#editFormID").serialize(),
                cache : false,
                type : "post",
            }).done(
                function(res) {
                    if (res > 0) {
                        toastrStyle();
                        toastr.success('修改成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function(res) {
                    toastrStyle();
                    toastr.error('修改失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        });

        /**
         * 通用表单提交(AJAX方式)(维修)
         */
        form.on('submit(repairForm)', function (data) {
            $.ajax({
                url : '${pageContext.request.contextPath}/spareParts/addSparePartsRepair.do',
                data: $("#repairFormID").serialize(),
                cache : false,
                type : "post",
            }).done(
                function(res) {
                    if (res > 0) {
                        toastrStyle();
                        toastr.success('维修提交成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function(res) {
                    toastrStyle();
                    toastr.error('维修提交失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        });

        $('#downloadFile').click(function(){
            layer.confirm('确认下载模板吗？', function(index){
                var url = "${pageContext.request.contextPath }/spareParts/exportFileMethod.do"
                window.location.href = url;
                layer.close(index);
            });
        });

        //进货日期
        laydate.render({
            elem: '#inProductTime1'
        });

        //进货日期
        laydate.render({
            elem: '#inProductTime2'
        });

        //维修开始时间
        laydate.render({
            elem: '#repairStartTime'
        });

        //维修结束时间
        laydate.render({
            elem: '#repairEndTime'
        });

        /**
         * 新增表单校验
         */
        form.verify({
            //value：表单的值item：表单的DOM对象
            productNo: function(value, item){
                if(value == ''){
                    return '产品编号不能为空';
                }
            },
            productName: function(value, item){
                if(value == ''){
                    return '产品名称不能为空';
                }
            },
            productCount: function(value, item){
                if(value == ''){
                    return '产品数量不能为空';
                }
            },
            remark01: function(value, item){
                if(value == ''){
                    return '安全库存不能为空';
                }
            },
        });

        //查找带回
        form.on('select(displayInfo)', function(data){
            $.ajax({
                type: 'POST',
                url: '${pageContext.request.contextPath}/spareParts/querySparePartsByProductNo.do',
                data: {productNo:$('#productNo').val()},
                /* dataType: 'json', */
                /* async: false, */
                success: function (data){
                    var spareParts = eval('(' +data+ ')');
                    //console.log(spareParts.productName);
                    $('#productName').val(spareParts.productName);
                }
            });
        });

        //指定允许上传的文件类型
        upload.render({
            elem: '#import'
            ,url: '${pageContext.request.contextPath }/shedu/uploadPlan.do'
            ,accept: 'file' //普通文件
            ,method: 'POST'
            ,field: "file"
            ,before: function(obj){
                layer.load();
            }
            ,done: function(res){
                //上传完毕回调
                layer.closeAll('loading');
                if (res >0) {
                    toastr.success('上传成功！');
                    setTimeout(function(){
                        window.location.reload();
                    },2000);
                }else {
                    layer.closeAll('loading');
                    toastr.error('上传失败！');
                }
            }
            ,error: function(){//请求异常回调
                layer.closeAll('loading');
                toastr.error('网络异常，请稍后重试！');
            }
        });

        /* Excel导入 */
        form.on('submit(uplodeform)', function (data) {
            var formData = new FormData($("#uploadform")[0]);
            $.ajax({
                url: '${pageContext.request.contextPath}/spareParts/uplodeFileMethod.do' ,
                type: 'post',
                data: formData,
                //async: false,
                //cache: false,
                dataType:'JSON',
                contentType: false,
                processData: false,
                success: function (data) {
                    if (data == 1) {
                        toastr.success("文件导入成功！");
                        setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
                            window.location.reload();
                            $("#reset").click();
                        },1000);
                    }else if(data == -1){
                        toastr.warning("导入的数据不符合导入条件！");
                    }else{
                        toastr.warning("文件格式异常，文件导入失败！");
                    }
                },
                error: function (data) {
                    toastr.error("文件格式异常，文件导入失败！");
                }
            })
            return false;
        });
    });
    toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上

    //提示框样式
    function toastrStyle(){
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "newestOnTop": false,
            "progressBar": false,
            "positionClass": "toast-top-center",
            "preventDuplicates": false,
            "onclick": null,
            "showDuration": "5000",
            "hideDuration": "1000",
            "timeOut&quot": "100000",
            "extendedTimeOut": "0",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
    }

    //日期格式转换1
    function createTime(v){
        var date = new Date(v);
        var y = date.getFullYear();
        var M = date.getMonth()+1;
        M = M<10?'0'+M:M;
        var d = date.getDate();
        d = d<10?("0"+d):d;
        var h = date.getHours();
        h = h<10?("0"+h):h;
        var m = date.getMinutes();
        m = m<10?("0"+m):m;
        var str = y+"-"+M+"-"+d+" "+h+":"+m;
        return str;
    }
</script>

</body>
</html>